Optional Sprites.f

Requires Structs
Requires Tools
Requires Quicksort
Requires SORA\Blocks
Requires SORA\Motifs
Requires SORA\Vertices
Requires SORA\Vbufs
Requires SORA\Images2
Only Forth Definitions

icode xswap
   0 [ebp] ecx mov
   8 [ebp] eax mov
   ecx 8 [ebp] mov
   eax 0 [ebp] mov
   ret end-code

icode yswap
   ebx ecx mov
   4 [ebp] ebx mov
   ecx 4 [ebp] mov
   ret end-code


: xflip
   xswap 2>r 1 0 2- 2r> 1 0 2- ;
: yflip
   yswap 2>r 0 1 2- 2r> 0 1 2- ;
: xyflip
   1 1 2- 2swap ; \ 1 1 2- ;

0 Value (flip)
\ :macro rectarea      dup >r 2h@  r> 4 + 2h@ 2over 2+ ;

\ create flips   0 , ' xflip , ' yflip , ' xyflip ,
 create flips   0 , ' xswap , ' yswap , ' 2swap ,

:macro ?flip   cells flips + @ execute ;

:macro  area   2over 2+ ;

: slow-sprite  ( subimage transform -- )
   locals| t spr  |
   spr rect@ area
   t ->z @
   spr 8 + h@ negate  spr 10 + h@ negate  \ t 2transform
   spr 4 +  2h@  area  (flip) ?flip
   t transformed-quad2d ;

: fast-sprite  ( subimage transform -- )
   locals| t spr |
   spr 2h@
   spr 4 + 2h@ 2over 2+
   t ->z @
   t ->x 2v@   spr 8 + 2h@ 2-   spr 4 + 2h@ 2over 2+
   quad2d ;

: sprite  ( subimage transform -- )
   dup ->color @ rgba  dup  ->roll @   over ->scale ->x @  or  (flip) or  if
      slow-sprite else fast-sprite then ;

